import express, { Request, Response } from 'express';
import bodyParser from 'body-parser';
import cookieParser from 'cookie-parser';
import path from 'path';
import cors from 'cors';
import socket from './utils/socket';
import mongodb from './utils/mongodb';
import appConfig from './config/appConfig';

const app: express.Express = express();

app.set('views', path.join(__dirname, '../views/'));
app.set('view engine', 'ejs');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, '../public/')));
app.use(cookieParser());
app.use(cors());

appConfig.route(app);

const port: string | number = process.env.PORT || 3000;
let server = app.listen(port, () => {
    console.log('http://127.0.0.1:' + port);
})

let socketIo = new socket(server);
socketIo.connect();

mongodb.connect();